package com.matt.remoteCall.impl;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.matt.commons.dto.sso.AreaDTO;
import com.matt.commons.dto.sso.StaffDTO;
import com.matt.commons.exception.BusinessException;
import com.matt.commons.model.ErrorCode;
import com.matt.commons.model.StatusResponse;
import com.matt.commons.page.PagerQuery;
import com.matt.commons.utils.MapConvertUtil;
import com.matt.commons.utils.ModelUtil;
import com.matt.commons.utils.RemoteCallUtil;

import com.matt.controller.po.ChildMemberPo;
import com.matt.domain.ClassReviewVo;
import com.matt.domain.CourseProductVo;
import com.matt.domain.PageResult;
import com.matt.domain.ParentUser;
import com.matt.remoteCall.DTO.DictDataDTO;
import com.matt.remoteCall.DTO.RoleCountDO;
import com.matt.remoteCall.DTO.RoleDTO;
import com.matt.remoteCall.DTO.StaffPageDO;
import com.matt.remoteCall.RemotePageCallUtil;
import com.matt.remoteCall.SsoCallService;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.util.*;

;

/**
 * *******************************
 * Created by Ron.
 * form com.matt
 * on 2018/6/25
 * *******************************
 */
@Service
@Slf4j
public class SsoCallServiceImpl implements SsoCallService {

    @Value("${sso.server.url}")
    private String ssoServerUrl;

    @Value("${server.gov.url}")
    private  String govUrl;

    //默认系统ID
    private static  final String  PLATFORM_ID = "a4c8daf5e4cc4eddb6e5b2393b2db110";
    //字典字段
    private static  final String  GLOBAL_SETTING = "milepost_item";
    //WEB-系统ID
    private static  final String  TERM_WEB = "a4c8daf5e4cc4eddb6e5b2393b2db110";
    //APP-系统ID
    private static  final String  TERM_APP = "1ec8b3dcf312488ead30f26e736d024e";
    //小程序-系统ID
    private static  final String  TERM_SMALL_ROUTINE = "a4c8daf5e4cc4eddb6e5b2393b2db110";


    public static void main(String[] args) {
        String ssoServerPlatformId =  "a4c8daf5e4cc4eddb6e5b2393b2db110";
        String platformId = "a4c8daf5e4cc4eddb6e5b2393b2db110";
        String ssoServerUrl =  "http://localhost:8090";
        String staffId = "94efaead3beb41a59bfd8424c27a7bfd";
        String staffId1 = "56e84a54d0de4e4fb971349a076c41dd";
        String[] ids = new String[]{"94efaead3beb41a59bfd8424c27a7bfd","0f6aa386835547628fb121692f069ab7"};
        String phone = "13808423855";
        String ticket = "c4f2d31bd27dc744fdf2d846f283c8be-a4c8daf5e4cc4eddb6e5b2393b2db110-1637119936996";
        String roleId = "cb723f6b686d45fa9c1db19b45098d5e";
        String oldPassword = "e10adc3949ba59abbe56e057f20f883e";
        String newPassword = "e10adc3949ba59abbe56e057f20f883e";
        String areaId = "4b68762b57df48018a3df813dc471570";
        String label = "00月02周 ~02月04周";  String value = "测试一下"; String type = "milepost_item";String description = "备注测试";String extension = "随便啦";
        String prefix = "00月02周";
        String labels = "00月,01月";
        String values = "测试二下,测试三下";
        String type1 = "测试1";
        String permission = "setting";

        String[] permission1 = new String[]{"setting","setting"};

//        Map map = JSON.parseObject(JSON.toJSONString(staffDTO), Map.class);

        Map map1 = new HashMap();
        map1.put("platformId",platformId);
        map1.put("password",oldPassword);
        map1.put("ip","ip");
        map1.put("mobile",phone);


        Map map2 = new HashMap();
        map2.put("areaId",areaId);
        map2.put("id",staffId);


        Map map = new HashMap();

        map.put("key",label);
        map.put("value",value);

        map.put("keys",labels);
        map.put("values",values);

        map.put("areaId",areaId);
        map.put("description",description);
        map.put("extension",extension);
        map.put("type",type1);


        Map map3 = new HashMap();

        map.put("key",label);
        map.put("value",value);

        map.put("keys",labels);
        map.put("values",values);

        map.put("areaId",areaId);
        map.put("description",description);
        map.put("extension",extension);
        map.put("type",type1);
        //邱峰
        String[] roleIds = new String[]{"2ec8beb9120442f18f0b41d8c8218c9d","0d8040eba0ff429c91f2a300ac729750"};
        String[] menuIds = new String[]{"c870d8c59cf34f7b8bc7754627d7f563","ae99ecba5e784cb0b2b7b6c7212b5117"};

        String[] areaIds = new String[]{"1","4b68762b57df48018a3df813dc471570"};
        RoleDTO role = new RoleDTO();
        role.setId("ef060b59bf4a407d9e6c02723b4bba83");
        role.setRoleCode("123");
        role.setRoleName("sso测试123");
        Map map12 = JSON.parseObject(JSON.toJSONString(role), Map.class);

        String platformId1 = getTermType(0);

        String result=String.join(",", areaIds);
        StaffDTO staffDTO = new StaffDTO();
        staffDTO.setMobile("13808423844");
        staffDTO.setGender(0);
        staffDTO.setLastLogin(new Date().getTime());
        Map staffDTOMap = MapConvertUtil.obejctToMap(staffDTO);
        String ticket1 = "cf9a13efe18123c6b801d9d84de8ae4a-a4c8daf5e4cc4eddb6e5b2393b2db110-1638756065122";
        String roleId1 = "2c90805b6b448a59016b4b9ef9b70439";
        Map param = new HashMap();
            param.put("pageNum",0);
            param.put("pageSize",10);
            param.put("roleId",roleId1);

        RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getAreaStaffList", param, ticket1, StaffPageDO.class, "调用sso推送消息出错");

        System.out.println(11);
    }

    @Override
    public StaffDTO getStaffDTO(String ticket) {

        log.info("GOT SSO SERVER URL ==== " + ssoServerUrl + "----ticket---- "+ticket);

        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_ticket_by_staff", null, ticket, StaffDTO.class, "调用sso获取用户信息出错");

    }

    @Override
    public StaffDTO getStaffDTO(String ticket, String staffId) {
         return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_staff_id_by_staff", ModelUtil.mapOf("staffId", staffId), ticket, StaffDTO.class, "调用sso获取用户信息出错");
    }

    @Override
    public StaffDTO getStaffDTOByPhone(String ticket, String phone) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_mobile_by_staff", ModelUtil.mapOf("mobile", phone), ticket, StaffDTO.class, "调用sso获取用户信息出错");
    }

    @Override
    public StaffDTO updateStaff(String ticket, StaffDTO staffDTO) {
        Map map = MapConvertUtil.obejctToMap(staffDTO); // JSON.parseObject(JSON.toJSONString(staffDTO), Map.class);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/update_staff", map, ticket, StaffDTO.class, "调用sso推送消息出错");
    }

    @Override
    public StaffDTO quitStaff(String ticket, String staffId){
        //TODO: 员工离职,需要根据ticket来圈定areaId
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/quitStaff",  ModelUtil.mapOf("staffId", staffId), ticket, StaffDTO.class, "调用sso推送消息出错");

    }

    @Override
    public StaffDTO createStaff(String ticket, StaffDTO staffDTO){
        Map map = MapConvertUtil.obejctToMap(staffDTO);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/createStaff", map, ticket, StaffDTO.class, "调用sso获取用户信息出错");
    }

    @Override
    public Map resetPassword(String ticket, String oldPassword, String newPassword) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/update_password",  ModelUtil.mapOf("oldPassword", oldPassword,"newPassword", newPassword), ticket, Map.class, "调用sso推送消息出错");
    }

    @Override
    public String passLogin(String mobile, String password, String ip, int term) {
        String platformId = getTermType(term);

        Map map = new HashMap();
        map.put("platformId",platformId);
        map.put("password",password);
        map.put("ip",ip);
        map.put("mobile",mobile);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/passLogin", map, null, String.class, "调用sso推送消息出错");
    }

    @Override
    public List<StaffDTO> getStaffDTOList(String ticket, String[] ids) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/ids_by_staff_list",  ModelUtil.mapOf("staffIds", Arrays.asList(ids)), ticket, StaffDTO.class, "调用sso推送消息出错");
    }

    @Override
    public List<StaffDTO> getStaffDTOList(String ticket, String permission) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getPermissionStaffDTOList",  ModelUtil.mapOf("permission", permission), ticket, StaffDTO.class, "调用sso推送消息出错");
    }

    @Override
    public List<StaffDTO> getStaffDTOList(String areaId) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getStaffDTOList",  ModelUtil.mapOf("areaId", areaId), null, StaffDTO.class, "调用sso推送消息出错");
    }

    @Override
    public Map getPermissionInfoV2(String ticket){
        return getPermissionInfoV2(ticket, 0 );
    }

    @Override
    public Map getPermissionInfoV2(String ticket, int term) {
        String platformId = getTermType(term);
        Map map = new HashMap();
        map.put("platformId", platformId);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getPermissionInfoV2", map, ticket, Map.class, "调用sso推送消息出错");
    }

    @Override
    public RoleDTO getStaffRole(String ticket) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getStaffRole", null, ticket, RoleDTO.class, "调用sso推送消息出错");
    }

    @Override
    public RoleDTO setDefaultRole(String ticket, String roleId) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/setDefaultRole", ModelUtil.mapOf("roleId",roleId), ticket, RoleDTO.class, "调用sso推送消息出错");

    }

    @Override
    public RoleDTO getDefaultRole(String ticket) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getDefaultRole", null, ticket, RoleDTO.class, "调用sso推送消息出错");
    }

    @Override
    public List<RoleDTO> getStaffRoleList(String ticket) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getStaffRoleList", null, ticket, RoleDTO.class, "调用sso推送消息出错");

    }

    //TODO: 需要处理的接口
    @Override
    public List<RoleDTO> getStaffRoleList(String ticket, String staffId) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getStaffIdByRoleList", ModelUtil.mapOf("staffId", staffId), ticket, RoleDTO.class, "调用sso推送消息出错");

    }

    @Override
    public void setStaffRoleList(String ticket, String staffId, String[] roleIds) {
        RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/setStaffRoleList", ModelUtil.mapOf("staffId", staffId,"roleIds",  Arrays.asList(roleIds)), ticket, null, "调用sso推送消息出错");
    }


    @Override
    /**
     * 添加用户 园区 角色菜单关系
     */
    public RoleDTO setRoleMenus(String ticket, String roleId, String[] menuIds, int term) {
        String platformId = getTermType(term);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/setRoleMenus",  ModelUtil.mapOf("roleId", roleId,"menuIds",  Arrays.asList(menuIds),"platformId", platformId), ticket, RoleDTO.class, "调用sso推送消息出错");
    }

    @Override
    public List<RoleCountDO> getAreaRoles(String ticket, boolean staffCount) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getAreaRoles", null, ticket, RoleCountDO.class, "调用sso推送消息出错");

    }

    @Override
    public RoleDTO addAreaRole(String ticket, RoleDTO role) {
        Map map = JSON.parseObject(JSON.toJSONString(role), Map.class);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/addAreaRole", map, ticket, RoleDTO.class, "调用sso推送消息出错");
    }

    @Override
    public void removeAreaRole(String ticket, RoleDTO role) {
        Map map = JSON.parseObject(JSON.toJSONString(role), Map.class);
        RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/removeAreaRole", map, ticket, null, "调用sso推送消息出错");

    }

    @Override
    public RoleDTO updateAreaRole(String ticket, RoleDTO role) {
        Map map = JSON.parseObject(JSON.toJSONString(role), Map.class);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/addAreaRole", map, ticket, RoleDTO.class, "调用sso推送消息出错");

    }

//    @Override
//    public List<StaffDTO> getAreaStaffByRole(String ticket, String roleId, PagerQuery pagerQuery) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getAreaStaffByRole", ModelUtil.mapOf("pageNum",pagerQuery.getPageNum(),"pageSize",pagerQuery.getPageSize(),"roleId",roleId), ticket, StaffDTO.class, "调用sso推送消息出错");
//    }

    @Override
    public Boolean checkStaffPermission(String ticket, String[] permission) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/checkStaffPermission",  ModelUtil.mapOf("permission", Arrays.asList(permission)), ticket, Boolean.class, "调用sso推送消息出错");
    }

    @Override
    public Boolean send_sms(String mobile) {
        return null;
    }

    @Override
    public Boolean validSmsCode(String phone, String code) {
        return null;
    }

    @Override
    public AreaDTO getAreaDTO(String ticket) {
       return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getAreaDTO", null, ticket, AreaDTO.class, "调用sso获取园区出错");
    }

    @Override
    public List<AreaDTO> getStaffGroupByAreaList(String ticket) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getStaffGroupByAreaList", null, ticket, AreaDTO.class, "调用sso推送消息出错");
    }

    @Override
    public List<String> getNormalStaffIdByArea(String ticket, String areaId) {
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getNormalStaffIdByArea", ModelUtil.mapOf("areaId",areaId), ticket, String.class, "调用sso推送消息出错");
    }

    @Override
    public List<StaffPageDO> getAreaStaffList(String ticket, String realName, String roleId, PagerQuery pagerQuery) {

        Map param = new HashMap();
        if (pagerQuery != null){
            param.put("pageNum",pagerQuery.getPageNum());
            param.put("pageSize",pagerQuery.getPageSize());
        }
        if (StringUtils.isNotEmpty(roleId)){
            param.put("roleId",roleId);
        }
        if (StringUtils.isNotEmpty(realName)){
            param.put("realName",realName);
        }

        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getAreaStaffList", param, ticket, StaffPageDO.class, "调用sso推送消息出错");
    }

    @Override
    public List<StaffPageDO> getAreaStaffListByPermission(String ticket, String permission, PagerQuery pagerQuery){
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getAreaStaffListByPermission", ModelUtil.mapOf("pageNum",pagerQuery.getPageNum(),"pageSize",pagerQuery.getPageSize(),"permission",permission), ticket, StaffPageDO.class, "调用sso推送消息出错");
    }


    public  static  String getTermType(int term){
        if (term ==0){
            return  TERM_WEB;
        }
        if (term ==1){
            return  TERM_APP;
        }
        if (term ==2){
            return  TERM_SMALL_ROUTINE;
        }
        return "";
    }

    @Override
    public List<DictDataDTO> getDictData(String ticket, DictDataDTO dictData) {
        Map map = JSON.parseObject(JSON.toJSONString(dictData), Map.class);
        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/getDictData", map, ticket, DictDataDTO.class, "调用sso推送消息出错");
    }

    @Override
    public Integer addDictData(String ticket,DictDataDTO dictData) {
        Map map = JSON.parseObject(JSON.toJSONString(dictData), Map.class);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/addDictData", map, ticket, Integer.class, "调用sso推送消息出错");
    }

    @Override
    public Integer delDictData(String ticket,String dictCode) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/delDictData",  ModelUtil.mapOf("dictCode", dictCode), ticket, Integer.class, "调用sso推送消息出错");

    }

    @Override
    public Integer updateDictData(String ticket,DictDataDTO dictData) {
        Map map = JSON.parseObject(JSON.toJSONString(dictData), Map.class);
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/updateDictData", map, ticket, Integer.class, "调用sso推送消息出错");
    }

    @Override
    public DictDataDTO dictCodeByDictData(String ticket, String dictCode) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/dictCodeByDictData",  ModelUtil.mapOf("dictCode", dictCode), ticket, DictDataDTO.class, "调用sso推送消息出错");
    }

    @Override
    public Map getStaffNameAndAreaName(String staffId, String areaId) {
        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getStaffNameAndAreaName",  ModelUtil.mapOf("staffId", staffId,"areaId", areaId), null, Map.class, "调用sso推送消息出错");
    }

    @Override
    public ParentUser getUserByMobile(String mobile) {
        return RemoteCallUtil.call(govUrl + "/api/sso/other_system/delDictData",  ModelUtil.mapOf("mobile", mobile), null, ParentUser.class, "调用gov推送消息出错");
    }

    @Override
    public ChildMemberPo addChildMember(ChildMemberPo po1) {
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpPost httpPost = new HttpPost(govUrl + "/api/tuoApi/childMember/addChildMemberByCrm");

        try {
            httpPost.setHeader("Content-Type", "application/json;charset=utf-8");
            String jsonBody = JSON.toJSONString(po1);
            StringEntity entity = new StringEntity(jsonBody, "UTF-8");
            httpPost.setEntity(entity);

            CloseableHttpResponse response = httpClient.execute(httpPost);
            HttpEntity responseEntity = response.getEntity();
            String responseJson = EntityUtils.toString(responseEntity, "UTF-8");

            if (response.getStatusLine().getStatusCode() != 200) {
                throw new BusinessException("999999", "HTTP状态码：" + response.getStatusLine().getStatusCode());
            }

            ObjectMapper objectMapper = new ObjectMapper();
            StatusResponse statusResponse = objectMapper.readValue(responseJson, StatusResponse.class);

            if (statusResponse.getCode().equals(ErrorCode.SUCCESSFUL)) {
                // 步骤1：打印data的实际值（调试用，确认后可删除）
                Object data = statusResponse.getData();
                log.info("远程接口data类型：{}，值：{}", data.getClass().getSimpleName(), data);

                // 步骤2：根据实际data格式处理（此处data是字符串'0k'，无需转换为ChildMemberPo）
                if (data instanceof String) {
                    // 业务逻辑：接口调用成功，返回null或构造一个默认对象
                    log.info("新增续费成功，远程返回标识：{}", data);
                    return null; // 或根据需求返回new ChildMemberPo()
                } else {
                    // 若偶尔返回对象，仍尝试转换（兼容处理）
                    return objectMapper.convertValue(data, ChildMemberPo.class);
                }
            } else {
                throw new BusinessException(statusResponse.getCode(), statusResponse.getMsg());
            }

        } catch (Exception e) {
            log.error("调用gov接口出错", e);
            throw new BusinessException("999998", "调用gov新增续费接口出错");
        } finally {
            try { httpClient.close(); } catch (Exception e) { log.warn("关闭客户端失败", e); }
        }
    }

    @Override
    public List<CourseProductVo> selectProduct(String ticket) {
        Map param = new HashMap();
        param.put("pageNum",1);
        param.put("pageSize",999);
        List<CourseProductVo> voList = RemoteCallUtil.callOfList(govUrl + "/api/tuoApi/CourseProduct/courseListByCrm", param, ticket, CourseProductVo.class, "调用gov推送消息出错");

        // 2. 修复name字段的中文乱码（核心步骤）
        if (voList != null) {
            for (CourseProductVo vo : voList) {
                String name = vo.getName();
                if (name != null) {
                    try {
                        // 关键：将ISO-8859-1编码的乱码转换为UTF-8
                        name = new String(name.getBytes(StandardCharsets.ISO_8859_1), StandardCharsets.UTF_8);
                        vo.setName(name);
                    } catch (Exception e) {
                        // 转换失败时保留原始值，避免报错
                        log.warn("修复name乱码失败：{}", name, e);
                    }
                }
            }
        }
        return voList;
    }

    @Override
    public PageResult<ClassReviewVo> selectReview(String leadsId, Integer pageNum, Integer pageSize, String ticket) {
        // 1. 准备业务参数（非分页参数）
        Map<String, Object> otherParams = new HashMap<>();
        otherParams.put("childrenId", leadsId); // 对应远程接口的childrenId参数

        // 2. 调用支持分页的远程方法
        return RemotePageCallUtil.callPage(
                govUrl + "/api/tuoApi/classReview/reviewListByCrm", // 远程接口地址
                pageNum,                                           // 页码
                pageSize,                                          // 页大小
                otherParams,                                        // 业务参数
                ticket,                                            // 认证票据
                ClassReviewVo.class,                               // 目标数据类型
                "调用gov评价记录接口出错"                          // 错误提示
        );
    }

    //public static final String KEY = "matt";


//    @Override
//    public Map getPermissionInfo(String ticket, String platformId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/permission_info?", ModelUtil.mapOf("platformId", platformId), ticket, Map.class, "调用sso获取用户权限出错");
//    }
//
//    @Override
//    public Map getPermissionInfoV2(String ticket, String platformId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/permission_info_v2", ModelUtil.mapOf("platformId", platformId), ticket, Map.class, "调用sso获取用户权限出错");
//    }
//
//    @Override
//    public StaffBaseDTO getBaseInfo(String ticket) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/base_info", null, ticket, StaffBaseDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public Map getInfo(String ticket) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/info", null, ticket, Map.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public StaffDTO getStaffDTO(String ticket) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/get_staff_dto?", null, ticket, StaffDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public StaffDTO getStaffDTOById(String staffId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_staff_dto", ModelUtil.mapOf("staffId", staffId), null, StaffDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public StaffDTO getStaffDTOByPhone(String phone) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_staff_dto_by_phone", ModelUtil.mapOf("phone", phone), null, StaffDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public List<StaffDTO> getStaffDTOList(String[] ids) {
//        String temp = Lists.newArrayList(ids).toString();
//        String id = temp.substring(1, temp.length() - 1);
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/un_login/list_by_ids", ModelUtil.mapOf("ids", id), null, StaffDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public List<StaffAreaDTO> getStaffByPlatformAndRoleAndArea(String platformId, String[] roleCode, String areaId) {
//        String temp = Lists.newArrayList(roleCode).toString();
//        String roleList = temp.substring(1, temp.length() - 1);
//        Map params = ModelUtil.mapOf(Lists.newArrayList("platformId", "roleCode", "areaId"), Lists.newArrayList(platformId, roleList, areaId));
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/un_login/get_staff_by_role", params, null, StaffAreaDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public List<StaffAreaDTO> getStaffExcludeRole(String platformName, String[] roleCode, String ticket) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("platformName", "roleCode"), Lists.newArrayList(platformName, Lists.newArrayList(roleCode)));
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/staff/exclude_role", params, ticket, StaffAreaDTO.class, "调用sso获取用户信息出错");
//    }
//
//    @Override
//    public Boolean send_sms(String mobile) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/un_login/send_sms", ModelUtil.mapOf("phone", mobile), null, Boolean.class, "调用sso发送短信出错");
//    }
//
//    @Override
//    public String padDingDingLogin(String dingDingCode, String ip) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/pad/un_login/ding_ding_login", ModelUtil.mapOf("value", dingDingCode, "ip", ip), null, String.class, "调用sso钉钉登录出错");
//    }
//
//    @Override
//    public String padPasswordLogin(String staffId, String simplePassword, String ip) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("staffId", "password", "ip"), Lists.newArrayList(staffId, simplePassword, ip));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/pad/un_login/pass_login", params, null, String.class, "调用sso密码登录出错");
//    }
//
//    @Override
//    public String padCodeLogin(String mobile, String code, String ip) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("mobile", "value", "ip"), Lists.newArrayList(mobile, code, ip));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/pad/un_login/code_login", params, null, String.class, "调用sso手势密码登录出错");
//    }
//
//    @Override
//    public Map padResetPassword(String ticket, String password) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/pad/un_login/reset_password", ModelUtil.mapOf("password", password), ticket, Map.class, "调用sso重置密码出错");
//    }
//
//    @Override
//    public List<AreaDTO> getAllArea() {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/un_login/get_all_area", null, null, AreaDTO.class, "调用sso获取所有园区出错");
//    }
//
//    @Override
//    public AreaDTO getAreaById(String areaId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_area", ModelUtil.mapOf("areaId", areaId), null, AreaDTO.class, "调用sso获取园区信息出错");
//    }
//
//    @Override
//    public List<Map> getInChargeArea(String ticket) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/staff/in_charge_area", null, ticket, Map.class, "调用sso获取负责园区出错");
//    }
//
//    @Override
//    public Boolean changeArea(String ticket, String areaId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/change_area", ImmutableMap.of("areaId", areaId), ticket, Boolean.class, "调用sso修改园区出错");
//    }
//
//    @Override
//    public Map submitDeviceInfo(String deviceId, String systemName, String platform, String version) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("deviceId", "systemName", "platform", "version"), Lists.newArrayList(deviceId, systemName, platform, version));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/device_info", params, null, Map.class, "调用sso获取版本信息出错");
//    }
//
//    @Override
//    public Boolean modifyHeadImg(String ticket, String imgUrl) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/modify_head_img", ModelUtil.mapOf("imgUrl", imgUrl), ticket, Boolean.class, "调用sso修改头像出错");
//    }
//
////    @Override
////    public String getYinShiToken() {
////        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_yin_shi_token", null, null, String.class, "调用sso获取萤石云token出错");
////    }
//
//    @Override
//    public String getAreaYinShiToken(String areaId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_area_yin_shi_token",  ModelUtil.mapOf("areaId", areaId), null, String.class, "调用sso获取萤石云token出错");
//    }
//
//    @Override
//    public StaffRoleDO getStaffRole(String ticket) {
//        StaffRoleDO staffRoleDO = new StaffRoleDO();
//        HashMap call = RemoteCallUtil.call(ssoServerUrl + "/api/sso/phone/un_login/getStaffRole", ImmutableMap.of("ticket", ticket), null, HashMap.class, "获取用户角色出错");
//        System.out.println("call:"+call);
//        staffRoleDO = StaffRoleDO.of(call);
//        return staffRoleDO;
//    }
//
//    @Override
//    public StaffRoleDO getStaffRoleByStaffId(String staffId) {
//        StaffRoleDO staffRoleDO = new StaffRoleDO();
//        HashMap call = RemoteCallUtil.call(ssoServerUrl + "/api/sso/phone/un_login/getStaffRoleByStaffId", ImmutableMap.of("staffId", staffId), null, HashMap.class, "获取用户角色出错");
//        System.out.println("==call:"+call);
//        staffRoleDO = StaffRoleDO.of(call);
//        return staffRoleDO;
//    }
//
//    @Override
//     public List<String> getLeaderByArea(String areaId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/phone/un_login/getAreaLeader", ModelUtil.mapOf("areaId", areaId), null, String.class, "调用sso获取园区负责人出错");
//    }
//    @Override
//    public List<String> getLeaderStaffIdByArea(String areaId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/phone/un_login/getLeaderStaffIdByArea", ModelUtil.mapOf("areaId", areaId), null, String.class, "调用sso获取园区负责人出错");
//    }
//
//
//    @Override
//    public List<String> getStaffIdByArea(String areaId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/phone/un_login/getStaffIdByArea", ModelUtil.mapOf("areaId", areaId), null, String.class, "调用sso获取园区员工出错");
//    }
//    //查询某园所未删除 未离职状态的员工ID
//    @Override
//    public List<String> getNomarlStaffIdByArea(String areaId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/phone/un_login/getNomarlStaffIdByArea", ModelUtil.mapOf("areaId", areaId), null, String.class, "调用sso获取园区员工出错");
//    }
//
//    @Override
//    public List<PlatformMenuDto> getPlatformMenu(String ticket, String platformId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/web/staff/platform_menu", ModelUtil.mapOf("platformId", platformId), ticket, PlatformMenuDto.class, "调用sso获取更新按钮信息出错");
//    }
//
//    @Override
//    public AreaSettingDTO getAreaSetting(String key, String areaId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/area_setting", ModelUtil.mapOf("key", key, "areaId", areaId), null, AreaSettingDTO.class, "调用sso获取园区设置");
//    }
//
//    @Override
//    public List<AreaSettingDTO> getAllAreaSettings(String areaId, String prefix){
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/all_area_settings", ModelUtil.mapOf("prefix", prefix, "areaId", areaId), null, List.class, "调用sso获取园区设置");
//    }
//
//    @Override
//    public Boolean addAreaSetting(String key, String value, String description, String extension, String areaId) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("key", "value", "description", "extension", "areaId"), Lists.newArrayList(key, value, description, extension, areaId));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/add_area_setting", params, null, Boolean.class, "调用sso设置园区配置信息出错");
//    }
//
//    @Override
//    public Integer addAreaSettings(String keys, String values, String description, String extension, String areaId) {
//        Map params = null;
//        if(StringUtils.isEmpty(extension) || StringUtils.isEmpty(description)){
//            params = ModelUtil.mapOf(Lists.newArrayList("key", "value", "areaId"), Lists.newArrayList(keys, values, areaId));
//        }else{
//            params = ModelUtil.mapOf(Lists.newArrayList("key", "value", "description", "extension", "areaId"), Lists.newArrayList(keys, values, description, extension, areaId));
//        }
//
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/add_area_settings", params, null, Integer.class, "调用sso设置园区配置信息出错");
//    }
//
//    @Override
//    public List<WorkDayDTO> getWorkDayList(String begin, String end) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/work_day_list", ModelUtil.mapOf("begin", begin, "end", end), null, WorkDayDTO.class, "调用sso获取工作日出错");
//    }
//
//    @Override
//    public StaffRoleDTO getRoleByPlatform(String ticket, Integer platformType) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/staff/get_staff_role", ModelUtil.mapOf("platformType", platformType), ticket, StaffRoleDTO.class, "调用sso获取相关角色信息出错");
//    }
//
//    @Override
//    public boolean sendPushByAlias(PushMsgVo pushMsg, String appKey, String masterSecret) {
//        Map params = com.matt.commons.utils.ModelUtil.mapOf("msgVo", JsonUtil.toJson(pushMsg), "appKey", appKey, "masterSecret", masterSecret);
//        return RemoteCallUtil.call(ssoServerUrl + "/api/push/alia", params, null, Boolean.class, "调用sso推送消息出错");
//    }
//
//    @Override
//    public boolean sendPushByListAlias(List<PushMsgVo> pushMsg, String appKey, String masterSecret) {
//        Map params = com.matt.commons.utils.ModelUtil.mapOf("msgVos", JsonUtil.toJson(pushMsg), "appKey", appKey, "masterSecret", masterSecret);
//        return RemoteCallUtil.call(ssoServerUrl + "/api/push/alias", params, null, Boolean.class, "调用sso推送消息出错");
//
//    }
//
//    @Override
//    public boolean sendPushByTags(List<PushMsgVo> pushMsgVos, String appkey, String masterSecret) {
//        Map params = com.matt.commons.utils.ModelUtil.mapOf("msgVos", JsonUtil.toJson(pushMsgVos), "appKey", appkey, "masterSecret", masterSecret);
//        return RemoteCallUtil.call(ssoServerUrl + "/api/push/tags", params, null, Boolean.class, "调用sso推送消息出错");
//    }
//
//    @Override
//    public Object getAllAreaWithType() {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/un_login/get_area_with_type", null, null, ArrayList.class, "sso通信出错");
//    }
//
//    @Override
//    public List<RelStaffPositionDTO> getAllStaffPositionInfo(String positionCode) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/get_all_staff_by_code", ModelUtil.mapOf("positionCode", positionCode), null, RelStaffPositionDTO.class, "调用sso获取工作日出错");
//    }
//
//    @Override
//       public List<RelStaffPositionDTO> getAreaStaffPositionInfo(String positionCode, String ticket) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/get_area_staff_by_code", ModelUtil.mapOf("positionCode", positionCode), ticket, RelStaffPositionDTO.class, "调用sso获取工作日出错");
//    }
//
//    @Override
//    public List<RelStaffPositionPlatformDTO> getStaffPositionList(String platformId, String ticket) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/get_staff_position_list", ModelUtil.mapOf("platformId", platformId), ticket, RelStaffPositionPlatformDTO.class, "调用sso获取用户岗位列表出错");
//    }
//
//
//    @Override
//    public Map getContentDownload(String ticket, Integer page, Integer size) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_download_list", ModelUtil.mapOf("page", page, "size", size), ticket, Map.class, "调用sso获取下载列表失败");
//    }
//
//    @Override
//    public Boolean getIsTestUser(String staffId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/getIsTestUser", ModelUtil.mapOf("staffId", staffId), CommonConstant.AUTH_VALUE, Boolean.class, "调用sso查询是否是外部测试用户失败");
//    }
//
//    @Override
//    public String phonePassLogin(String mobile, String password, String ip) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("mobile", "password", "ip"), Lists.newArrayList(mobile, password, ip));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/pad/un_login/phoneLogin", params, null, String.class, "调用sso手机登录出错");
//    }
//
//    @Override
//    public Boolean validSmsCode(String phone, String code) {
//        Map params = ModelUtil.mapOf(Lists.newArrayList("phone", "value"), Lists.newArrayList(phone, code));
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/web/un_login/validSmsCode", params, null, Boolean.class, "调用短信验证码校验接口出错");
//    }
//
//
//    @Override
//    public StaffPositionDTO getStaffPositionInfo(String ticket,String staffId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/staff_position_by_staffId", ModelUtil.mapOf("staffId", staffId),ticket, StaffPositionDTO.class, "调用sso获取相关角色信息出错");
//    }
//
//    @Override
//    public DefaultStaffPositionDTO getDefaultStaffPositionInfo(String ticket,String staffId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/get_default_staff_position", ModelUtil.mapOf("staffId", staffId, "platformId", com.matt.foundation.constant.CommonConstant.TEACH_PLATFORM_ID),ticket, DefaultStaffPositionDTO.class, "调用sso获取相关角色信息出错");
//    }
//
//    @Override
//    public Map setDefaultStaffPosition(String ticket,String staffId,String deafultPositionId) {
//        return RemoteCallUtil.call(ssoServerUrl + "/api/sso/other_system/set_default_staff_position", ModelUtil.mapOf("staffId", staffId,"positionId",deafultPositionId),ticket, Map.class, "设置用户默认刚问出错");
//    }
//
//    @Override
//    public List<PlatformPositionDTO> getPlatformPositionList(String ticket) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/get_platfrom_position_list", null, ticket, PlatformPositionDTO.class, "获取平台岗位列表出错");
//    }
//
//    @Override
//    public List<PlatformRoleDO> getAreaStaffInfo(String ticket,String platformId,String areaId) {
//        return RemoteCallUtil.callOfList(ssoServerUrl + "/api/sso/other_system/get_area_staff_info", ModelUtil.mapOf("platformId", platformId,"areaId",areaId), ticket, PlatformRoleDO.class, "调用sso获取工作日出错");
//    }
  }
